/**
 * @Title: WechatJsUnitInterceptor.java
 * @Package com.leesche.zcsp.node.web.intecepter.wechat
 * @Description:()
 * @author dennies yang
 * @date 2016年10月23日 下午10:26:44
 * @version V1.0
 */
package com.leesche.zcsp.node.web.intecepter.wechat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.leesche.zcsp.node.pay.wecha.utils.SignUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.leesche.zcsp.node.pay.wecha.timer.WechatTimer;

/**
 * @Title: WechatJsUnitInterceptor.java
 * @Package com.leesche.zcsp.node.web.intecepter.wechat
 * @Description:()
 * @author dennies yang
 * @date 2016年10月23日 下午10:26:44
 * @version V1.0
 */
public class WechatJsUnitInterceptor extends HandlerInterceptorAdapter {
    private static final Logger logger = Logger.getLogger(WechatJsUnitInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if (!request.getMethod().equalsIgnoreCase("GET")) {
            return true;
        }
        String url = request.getScheme() + "://" + request.getServerName() + request.getRequestURI();
        System.out.println(url);
        if (StringUtils.isNotBlank(request.getQueryString())) {
            url = url + "?" + request.getQueryString();
        }
        logger.info("jstoken +" + url);
        request.setAttribute("jsret", SignUtil.sign(WechatTimer.JS_TIKET, url));
        return true;
    }
}
